package com.lnt.spring;

import com.lnt.spring.bean.User;
import com.lnt.spring.conversion.StringToUserConverter;
import com.lnt.spring.conversion.StringToUserPropertyEditor;
import org.springframework.core.convert.support.DefaultConversionService;

/**
 * @title : 脱离Spring单独运行的程序
 * @createDate : 2021-11-13 10:40
 * @creater : LuNanTing
 * @className : JavaTest
 */
public class JavaTest {

    public static void main(String[] args) {
        // JDK自带的类型转换服务单独使用
        JDKPropertyEdtior();

        // Spring自带的类型转换服务单独使用
        DefaultConversionService defaultConversionService = new DefaultConversionService();
        defaultConversionService.addConverter(new StringToUserConverter());
        User user = defaultConversionService.convert("李四", User.class);
        System.out.println(user);

    }

    private static void JDKPropertyEdtior() {
        // jdk自带的类型转换器使用
        StringToUserPropertyEditor stringToUserPropertyEditor = new StringToUserPropertyEditor();
        stringToUserPropertyEditor.setAsText("a");
        User value = (User)stringToUserPropertyEditor.getValue();
        System.out.println(value);
    }
}
